import {MigrationInterface, QueryRunner} from "typeorm";

export class Test1600062330134 implements MigrationInterface {
    name = 'Test1600062330134'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query("DROP INDEX `IDX_4a74ca47fe1aa34a28a6db3c72` ON `role`");
        await queryRunner.query("ALTER TABLE `role` CHANGE `role` `title` varchar(11) NOT NULL COMMENT '身份角色'");
        await queryRunner.query("ALTER TABLE `role` ADD UNIQUE INDEX `IDX_4a74ca47fe1aa34a28a6db3c72` (`title`)");
        await queryRunner.query("ALTER TABLE `role` CHANGE `is_del` `is_del` tinyint NOT NULL COMMENT '是否可以删除，0-可以，1-不可以' DEFAULT 0");
        await queryRunner.query("ALTER TABLE `user` CHANGE `is_del` `is_del` tinyint NOT NULL COMMENT '是否可删除，0-可以，1-不可以' DEFAULT 0");
        await queryRunner.query("ALTER TABLE `posts` CHANGE `is_del` `is_del` tinyint NOT NULL COMMENT '是否可以删除，0-可以，1-不可以' DEFAULT 0");
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query("ALTER TABLE `posts` CHANGE `is_del` `is_del` tinyint NOT NULL COMMENT '是否可以删除，0-可以，1-不可以' DEFAULT '0'");
        await queryRunner.query("ALTER TABLE `user` CHANGE `is_del` `is_del` tinyint NOT NULL COMMENT '是否可删除，0-可以，1-不可以' DEFAULT '0'");
        await queryRunner.query("ALTER TABLE `role` CHANGE `is_del` `is_del` tinyint NOT NULL COMMENT '是否可以删除，0-可以，1-不可以' DEFAULT '0'");
        await queryRunner.query("ALTER TABLE `role` DROP INDEX `IDX_4a74ca47fe1aa34a28a6db3c72`");
        await queryRunner.query("ALTER TABLE `role` CHANGE `title` `role` varchar(11) NOT NULL COMMENT '身份角色'");
        await queryRunner.query("CREATE UNIQUE INDEX `IDX_4a74ca47fe1aa34a28a6db3c72` ON `role` (`role`)");
    }

}
